//
//  UIView+IBExtension.swift
//  Project03-Weibo-swift
//
//  Created by w on 16/1/18.
//  Copyright © 2016年 w. All rights reserved.
//

import UIKit

///  @IBInspectable的练习，给UIView添加计算属性,方便其在Interface Builder中显示

extension UIView {
    
    @IBInspectable var borderWidth:CGFloat {
        set {
            layer.borderWidth = newValue
        }
        get {
            return layer.borderWidth
        }
    }
    
    @IBInspectable var borderColor:UIColor? {
        set {
            layer.borderColor = newValue?.CGColor
        }
        get {
            if layer.borderColor != nil {
                //由于layer.borderColor为可选值，所以定义的属性也为可选值
                return UIColor(CGColor: layer.borderColor!)
            }
            return nil
        }
    }
    
    @IBInspectable var cornerRadius:CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0 //让圆角立即生效
        }
    }
}
